package com.example.basic.web.controller.notice;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.notice.InNotice;
import com.example.basic.web.response.InNoticeResponse;
import com.example.basic.web.service.notice.InNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Api(value  = "入库通知单", tags = {"入库通知单"})
@RestController
@RequestMapping("/api/v1/byg/inNotice")
public class InNoticeController {

    @Resource
    private InNoticeService inNoticeService;

    @Log(title = "入库通知单管理", description = "新增")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/batchAdd")
    public Result<Boolean> batchAdd(@ApiParam(name = "inNoticeList", value = "模型", required = true) @RequestBody List<InNotice> inNoticeList) {
        return ResultGenerator.genSuccessResult(inNoticeService.batchAdd(inNoticeList,false));
    }

    @Log(title = "入库通知单管理", description = "修改")
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/modify")
    public Result<InNotice> modify(@ApiParam(name = "inNotice", value = "模型", required = true) @RequestBody InNotice inNotice) {
        return ResultGenerator.genSuccessResult(inNoticeService.modify(inNotice));
    }

    @Log(title = "入库通知单管理", description = "详情")
    @ApiOperation(value = "详情", notes = "详情")
    @PostMapping("/detail")
    public Result<InNotice> detail(@ApiParam(name = "inNoticeCode", value = "入库通知单编码") @RequestParam String inNoticeCode) {
        return ResultGenerator.genSuccessResult(inNoticeService.detail(inNoticeCode));
    }

    @Log(title = "入库通知单管理", description = "删除")
    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public Result<Integer> delete(@ApiParam(name = "inNoticeCode", value = "入库通知单编码") @RequestParam String inNoticeCode ) {
        return ResultGenerator.genSuccessResult(inNoticeService.delete(inNoticeCode));
    }

    @Log(title = "入库通知单管理", description = "审核/取消审核")
    @ApiOperation(value = "审核/取消审核", notes = "审核/取消审核")
    @PostMapping("/auditOrCancel")
    public Result<Integer> auditOrCancel(
            @ApiParam(name = "inNotice", value = "模型", required = true) @RequestBody InNotice inNotice) {
        return ResultGenerator.genSuccessResult(inNoticeService.auditOrCancel(inNotice));
    }

    @Log(title = "入库通知单管理", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryList")
    public Result<IPage<InNoticeResponse>> queryList(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "sex", value = "性别 0-全部") @RequestParam(defaultValue = "0") String sex,
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode,
            @ApiParam(name = "beginTime", value = "开始日期") @RequestParam(required = false) String beginTime,
            @ApiParam(name = "endTime", value = "结束日期") @RequestParam(required = false) String endTime,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<InNoticeResponse> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(inNoticeService.queryList(queryPage,searchParam,sex,pharmCode,zoneCode,depotCode,beginTime,endTime));
    }
}
